<?php

/**
 * User-role model. A user can have more than one role.
 *
 * @author    Mon Zafra <monzee at gmail>
 * @copyright (c)2009 Mon Zafra
 * @license   http://monzee.wordpress.com/license New BSD
 * @version   $Id: UserRoles.php 38 2009-02-18 17:12:39Z monzee $
 */
class Admin_UserRoles
{
    protected $_userRoles = array();

    public function __construct()
    {
        $this->_userRoles = array(
            array(
                'user_id' => 1, // admin
                'role_id' => 1, // Administrator
            ),
            array(
                'user_id' => 2, // monzee
                'role_id' => 4, // Author
            ),
            array(
                'user_id' => 3, // anon
                'role_id' => 3, // Member
            ),
            array(
                'user_id' => 4, // foo
                'role_id' => 5, // Moderator
            ),
            array(
                'user_id' => 5, // superman
                'role_id' => 6, // Editor
            ),
            array(
                'user_id' => 6, // john
                'role_id' => 4, // Author
            ),
            array(
                'user_id' => 6, // john
                'role_id' => 5, // Moderator
            ),
            array(
                'user_id' => 7, // superadmin
                'role_id' => 1, // Administrator
            ),
            array(
                'user_id' => 7, // superadmin
                'role_id' => 4, // Author
            ),
            array(
                'user_id' => 7, // superadmin
                'role_id' => 5, // Moderator
            )
        );
    }

    public function setUserRoles($userRoles)
    {
        $this->_userRoles = $userRoles;
    }

    /**
     * Returns all the roles of a user
     * 
     * @param int $userId
     * @return array
     */
    public function getRolesByUserId($userId)
    {
        $userRoles = $this->_userRoles;
        $ret = array();
        foreach ($userRoles as $userRole) {
            if ($userRole['user_id'] == $userId) {
                $ret[] = $userRole['role_id'];
            }
        }

        return $ret;
    }

}
